function doSearch(){    
    $('#tt').datagrid('load', {    
    	isUseful : $('#isUseful').combobox('getValue')
    });
    $('#tt').datagrid('unselectAll');
}
$(function() {
	$('#isUseful').combobox("select",-1);
});
function add(){
    showMyWindow('增加模板', '/timemodel/add', 300, 200);
}


function isUsefulFunc(value) {
	if (value == 1) {
		return "启用";
	}
	if (value == 0) {
		return "作废";
	}

}


function edit(){
	var row = $('#tt').datagrid('getSelected');
	var id = row.id;
    if (row){
	    showMyWindow('编辑模板', '/timemodel/'+id+'/update', 300, 200);
    } else {
    	showMsg(market.content.title, market.content.tips, alert);
    }
}


function abandon() {
	var row = $('#tt').datagrid('getSelected');
	var id = row.id;
	var isUseful = row.isUseful;
	if(isUseful == 0){
		$.messager.alert(market.content.title,"数据已是废弃状态");
		return;
	}
	$.messager.confirm('温馨提醒', '你确定废弃本条数据吗？', function(r) {
		if (r) {
			$.post('/timemodel/update?id=' + id +'&isUseful=0', function(data) {
				if (data.return_code == '1') {
					top.showMsg(market.content.title, data.return_msg, alert);
					doSearch();
				} else if (data.return_code == '3') {
					top.showMsg(market.content.title, data.return_msg, alert);
				} else {
					$.messager.alert(market.content.title, data.return_msg);
				}
			});
		}
	});
}

function del() {
	var row = $('#tt').datagrid('getSelected');
	var id = row.id;
	$.messager.confirm('温馨提醒', '你确定删除本条数据吗？', function(r) {
		if (r) {
			$.get('/timemodel/del?id=' + id, function(data) {
				if (data.return_code == '1') {
					top.showMsg(market.content.title, data.return_msg, alert);
					doSearch();
				} else if (data.return_code == '3') {
					top.showMsg(market.content.title, data.return_msg, alert);
				} else {
					$.messager.alert(market.content.title, data.return_msg);
				}
			});
		}
	});
}

function effect() {
	var row = $('#tt').datagrid('getSelected');
	var id = row.id;
	var isUseful = row.isUseful;
	if(isUseful == 1){
		$.messager.alert(market.content.title,"数据已是启用状态");
		return;
	}
	$.messager.confirm('温馨提醒', '你确定启用本条数据吗？', function(r) {
		if (r) {
			$.post('/timemodel/update?id=' + id +'&isUseful=1', function(data) {
				if (data.return_code == '1') {
					top.showMsg(market.content.title, data.return_msg, alert);
					doSearch();
				} else if (data.return_code == '3') {
					top.showMsg(market.content.title, data.return_msg, alert);
				} else {
					$.messager.alert(market.content.title, data.return_msg);
				}
			});
		}
	});
}

function formatterModel(value, row, index) {
	var a = '<a href="#" onclick="editModel(' + "'" + row.id + "'" + ')">配置</a> ';
	return a;
}

function formatterTemplete(value, row, index) {
	var a = '<a href="#" onclick="editTemplete(' + "'" + row.id + "'" + ')">配置模板</a> ';
	return a;
}

function editModel(id){
	showMyWindow('模拟器配置| 编辑曲线配置', '/timemodel/' + id + '/editModel', 600, 400);
}

function editTemplete(id){
	showMyWindow('模拟器配置| 编辑曲线配置模板', '/timemodel/' + id + '/updateModel', 1200, 600);
}
